<?php
namespace app\task\controller;
use app\task\logic\DealWorkStationLogic;

/**
 * 处理工位/办公室
 * Created by PhpStorm.
 * User: tyll
 * Date: 2020/04/20
 * Time: 11:20
 */
class DealWorkStation extends Base {

    public function __construct(){
        parent::__construct();
        $this->dws_logic = new DealWorkStationLogic();
    }

    /**
     * 处理生成工位小程序码
     * @return \think\response\Json
     */
    public function deal_gen_ws_mini_code(){
        $wm = new \app\common\controller\WxMini();

        $maps = [];
        $maps[] = ['wechat_mini_code_pic','=',''];
        $list = model('work_station')->get_list($maps,'id','id asc','',0,10);
        foreach($list as $k => $v){
            $scene = 'spaceid=' . $v['id'];

            //生成小程序码
            $r = $wm->gen_mini_code($scene);
            if(!$r){
                return json($this->dws_logic->get_response(0,'处理生成工位小程序码，生成失败'));
            }

            $ws_maps = [];
            $ws_maps[] = ['id','=',$v['id']];

            $ws_data = [];
            $ws_data['wechat_mini_code_pic'] = $r;
            $r = model('work_station')->force()->save($ws_data,$ws_maps);
        }

        return json($this->dws_logic->get_response(1,'处理生成工位小程序码，总数量：' . count($list)));
    }
}
